﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Tilver.Coder.Core;

namespace Tilver.Coder.DBTextStyle
{
    /// <summary>
    /// 数据库文本样式抽象类
    /// </summary>
    public abstract class DBTextStyleBase
    {
        /// <summary>
        /// 数据库类型
        /// </summary>
        public DataProviderTypeEnum DataProviderType;

        /// <summary>
        /// 获取一个表的完整名称
        /// </summary>
        /// <param name="owner">架构名称</param>
        /// <param name="tableName">表名称</param>
        /// <returns></returns>
        public abstract string GetTableFullName(string owner, string tableName);

        /// <summary>
        /// 获取一个视图的完整名称
        /// </summary>
        /// <param name="owner">架构名称</param>
        /// <param name="viewName">视图名称</param>
        /// <returns></returns>
        public abstract string GetViewFullName(string owner, string viewName);

        /// <summary>
        /// 获取一个存储过程完整名称
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="commandName"></param>
        /// <returns></returns>
        public abstract string GetCommandFullName(string owner, string commandName);
        /// <summary>
        /// 去除变量前缀
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public abstract string Clean(string value);

        /// <summary>
        /// 获取列
        /// </summary>
        /// <param name="columnName">列名称</param>
        /// <returns></returns>
        public abstract string GetColumnName(string columnName);

        /// <summary>
        /// 在数据库中的参数的名称
        /// </summary>
        /// <param name="columnName">列名称</param>
        /// <returns></returns>
        public abstract string GetParameterName(string columnName);

        /// <summary>
        /// 在数据库中的参数的名称
        /// </summary>
        /// <param name="tableName">表名称</param>
        /// <param name="columnName">列名称</param>
        /// <returns></returns>
        public abstract string GetParameterName(string tableName, string columnName);

        /// <summary>
        /// 转换成c#中的默认值
        /// </summary>
        /// <param name="dataObject">数据对象</param>
        /// <returns></returns>
        public abstract string GetCSharpDefaultValue(CoderDataObject dataObject);

        /// <summary>
        /// 执行sql,返回DataSet
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="commandText"></param>
        /// <param name="commandType"></param>
        /// <param name="paras"></param>
        /// <returns></returns>
        public abstract DataSet ExecuteSql(string connectionString, string commandText, CommandType commandType, IEnumerable<CoderParameter> paras);
        /// <summary>
        /// 执行sql，返回DataSet
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="mo"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public abstract DataSet GetTopData(string connectionString, IMOGenerable mo, int count = 100);
        /// <summary>
        /// 返回取前几条数据的sql语句
        /// </summary>
        public abstract void WriteTopSql(int tabs, StringBuilder response);
        /// <summary>
        /// 返回Insert语句后的自增ID
        /// </summary>
        /// <returns></returns>
        public abstract string GetInsertIdentitySql();

    }
}
